package liu.de.service;

import liu.de.domain.TestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liude
 */
@SuppressWarnings("WeakerAccess")
@Service
public class MongoService {

    private final MongoTemplate mongoTemplate;

    @Autowired
    public MongoService(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }

    public List<TestBean> find(String name) {
        return mongoTemplate.find(new Query(Criteria.where("name").is(name)), TestBean.class);
    }

    public void save(TestBean testBean) {
        mongoTemplate.save(testBean);
    }
}
